// PersistentFacadeImp.h: interface for the PersistentFacadeImp class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PERSISTENTFACADEIMP_H__0C295B00_508A_40A3_89A9_32493414D7CC__INCLUDED_)
#define AFX_PERSISTENTFACADEIMP_H__0C295B00_508A_40A3_89A9_32493414D7CC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "PersistentFacade.h"
#include "PartDBParameterFormerSet.h"

class ProductCatalogItem  
{
public:
	ProductCatalogItem( const CString& id, const CString& dsuri ) : m_ID( id ), m_DSURI( dsuri ), m_Conn( 0 ) {}
	virtual ~ProductCatalogItem() {}

public:
	const CString& ID() const { return m_ID; }
	_ConnectionPtr* DataSourceConnection() { return m_Conn ? m_Conn : m_Conn 
		= DAWrapper::DBConnectionManager::Instance()->GetConnectionPtrByUri( m_DSURI ); }

private:
	void ID( const CString& id ) { m_ID = id; }
	void DataSourceURI( const CString& dsUri ) { m_DSURI = dsUri; }

private:
	CString m_ID;
	CString m_DSURI;
	_ConnectionPtr* m_Conn;
};

class AFX_EXT_CLASS PersistentFacadeImp : public PersistentFacade  
{
public:
	PersistentFacadeImp() : m_PCMConn( 0 ) {}
	virtual ~PersistentFacadeImp();

public:
	virtual JointRegularSet* GetJointRegularSet();
	virtual PartParameterFormerSet* GetPartParameterFormerSet();
	virtual PartCrudeDataSet* GetPartCrudeDataSet();
	virtual CurPartSet* GetCurPartSet();
	virtual SpringSet* GetSpringSet();
	virtual StandardGenerator* GetStandardGenerator();
	virtual ConstSpringDisSerialManager* GetConstSpringDisSerialManager();
	virtual ConstSpringSet* GetConstSpringSet();
	virtual ConstSpringJointPortSet* GetConstSpringJointPortSet();

	virtual void CloseConnection();
private:
	_ConnectionPtr* GetPCMConnection();
	_ConnectionPtr* GetProductCatalogConnection( const CString& pcid );

private:
	_ConnectionPtr* m_PCMConn;
	CArray<ProductCatalogItem*,ProductCatalogItem*> m_CatalogItems;
	PartFormerGenerator m_ParameterFormerSet;
	JointRegularSetGenerator m_JointRegularSet;
	PartCrudeDataSetGenerator m_PartCrudeDataSet;
	CurPartSetGenerator m_CurPartSet;
	SpringSetGenerator m_SpringSet;
	StandardGenerator m_StandardSet;
	ConstSpringDisSerialManager m_CSpringDisSerialManager;
	ConstSpringSet m_CSpringSet;
	ConstSpringJointPortSet m_CSpringJointPortSet;
};

#endif // !defined(AFX_PERSISTENTFACADEIMP_H__0C295B00_508A_40A3_89A9_32493414D7CC__INCLUDED_)
